package com.doudoukeji.service.Activity.my.edituser.edituserinf;

import android.content.Context;
import android.view.View;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;

import com.doudoukeji.service.Bean.ServiceLitapal;
import com.doudoukeji.service.R;
import com.sanhai.android.adapter.CommonAdapter;
import com.sanhai.android.adapter.ViewHolder;

import java.util.ArrayList;
import java.util.List;

/**
 * @version 2.0
 * @类描述：
 * @项目名称：ddgh
 * @类名称： EditUserInfAdapter
 * @包名称： com.doudoukeji.service.Activity.my.edituser.edituserinf
 * @创建人： zhanjunjie
 * @创建时间：2016/3/17 10:23
 * @修改人：
 * @修改时间：2016/3/17 10:23
 * @修改备注： new parent class(用一句话描述修改了什么)
 */
public class EditUserInfAdapter extends CommonAdapter<ServiceLitapal> {
    private List<String> stringList = new ArrayList<String>();
    private List<ServiceLitapal> data = new ArrayList<ServiceLitapal>();
    public EditUserInfAdapter(Context context, List<ServiceLitapal> datas,List<String> strings) {
        super(context, datas, R.layout.item_serve);
        this.stringList = strings;
        this.data =datas;
    }

    @Override
    public void convert(int position, ViewHolder helper, ServiceLitapal item) {
        TextView mTvServiceName = helper.getView(R.id.item_tvname);
        final TextView mTvServiceDesc = helper.getView(R.id.item_tvdescribe);
        CheckBox mCbService = helper.getView(R.id.item_cb);
        final ImageView mImgService = helper.getView(R.id.item_img);
        mImgService.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(mTvServiceDesc.getVisibility()==View.VISIBLE){
                    mTvServiceDesc.setVisibility(View.GONE);
                    mImgService.setImageResource(R.drawable.icon_aworr_bottom);
                }else{
                    mTvServiceDesc.setVisibility(View.VISIBLE);
                    mImgService.setImageResource(R.drawable.icon_aworr_top);
                }
            }
        });
        mCbService.setChecked(false);
        if(stringList.size()>0){
            for (int x= 0;x<stringList.size();x++){
                if (stringList.get(x).equals(item.getServiceid())) {
                    mCbService.setChecked(true);
                }
            }
        }
        mTvServiceName.setText(data.get(position).getName());
        mTvServiceDesc.setText(data.get(position).getMemo());
    }
}
